const Service = require('egg').Service;

class AdminService extends Service {
    async find(uid) {
        const user = await this.app.mysql.get('bit_user', { id: uid });
        return user;
    }
    async find(uid) {
        const user = await this.app.mysql.get('bit_user', { id: uid });
        return user;
    }
    //content1
    async createContent1(data) {
        const result = await this.app.mysql.insert('content1', data);
        return result;
    }
    async showcontent1() {
        const result = await this.app.mysql.select('content1');
        return result;
    }
    async delcontent1(id) {
        const result = await this.app.mysql.delete('content1', { id: id });
        return result;
    }
    //content2
    async createContent2(data) {
        const result = await this.app.mysql.insert('content2', data);
        return result;
    }
    async showcontent2() {
        const result = await this.app.mysql.select('content2');
        return result;
    }
    async delcontent2(id) {
        const result = await this.app.mysql.delete('content2', { id: id });
        return result;
    }
    //content3
    async createContent3(data) {
        const result = await this.app.mysql.insert('content3', data);
        return result;
    }
    async showcontent3() {
        const result = await this.app.mysql.select('content3');
        return result;
    }
    async delcontent3(id) {
        const result = await this.app.mysql.delete('content3', { id: id });
        return result;
    }
    //content4
    async createContent4(data) {
        const result = await this.app.mysql.insert('content4', data);
        return result;
    }
    async showcontent4() {
        const result = await this.app.mysql.select('content4');
        return result;
    }
    async delcontent4(id) {
        const result = await this.app.mysql.delete('content4', { id: id });
        return result;
    }
    //content5
    async createContent5(data) {
        const result = await this.app.mysql.insert('content5', data);
        return result;
    }
    async showcontent5() {
        const result = await this.app.mysql.select('content5');
        return result;
    }
    async delcontent5(id) {
        const result = await this.app.mysql.delete('content5', { id: id });
        return result;
    }
    //image1
    async createImage1(data) {
        const result = await this.app.mysql.insert('image1', data);
        return result;
    }
    async showImage1() {
        const result = await this.app.mysql.select('image1');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }

        return result;
    }
    async delImage1(id) {
        const result = await this.app.mysql.delete('image1', { id: id });
        return result;
    }
    //image2
    async createImage2(data) {
        const result = await this.app.mysql.insert('image2', data);
        return result;
    }
    async showImage2() {
        const result = await this.app.mysql.select('image2');
       // console.log(result);
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage2(id) {
        const result = await this.app.mysql.delete('image2', { id: id });
        return result;
    }
    //image3
    async createImage3(data) {
        const result = await this.app.mysql.insert('image3', data);
        return result;
    }
    async showImage3() {
        const result = await this.app.mysql.select('image3');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage3(id) {
        const result = await this.app.mysql.delete('image3', { id: id });
        return result;
    }
    //image4
    async createImage4(data) {
        const result = await this.app.mysql.insert('image4', data);
        return result;
    }
    async showImage4() {
        const result = await this.app.mysql.select('image4');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage4(id) {
        const result = await this.app.mysql.delete('image4', { id: id });
        return result;
    }
    //image5
    async createImage5(data) {
        const result = await this.app.mysql.insert('image5', data);
        return result;
    }
    async showImage5() {
        const result = await this.app.mysql.select('image5');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage5(id) {
        const result = await this.app.mysql.delete('image5', { id: id });
        return result;
    }
    //image6
    async createImage6(data) {
        const result = await this.app.mysql.insert('image6', data);
        return result;
    }
    async showImage6() {
        const result = await this.app.mysql.select('image6');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage6(id) {
        const result = await this.app.mysql.delete('image6', { id: id });
        return result;
    }
    //image7
    async createImage7(data) {
        const result = await this.app.mysql.insert('image7', data);
        return result;
    }
    async showImage7() {
        const result = await this.app.mysql.select('image7');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage7(id) {
        const result = await this.app.mysql.delete('image7', { id: id });
        return result;
    }
    //image8
    async createImage8(data) {
        const result = await this.app.mysql.insert('image8', data);
        return result;
    }
    async showImage8() {
        const result = await this.app.mysql.select('image8');
        if (result.length > 0) {
            for (let image of result) {
                image.state = 0;
            }
            result[0].state = 1;
        }
        return result;
    }
    async delImage8(id) {
        const result = await this.app.mysql.delete('image8', { id: id });
        return result;
    }
}
module.exports = AdminService;